package com.listeningframework.boot.autoconfigure.session;

import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.Session;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.http.HttpSessionStrategy;

/**
 * <p>
 * 1. we would point our connection to an external Redis instance.
 * 
 * 2. The @EnableRedisHttpSession annotation creates a Spring Bean
 * with the name of springSessionRepositoryFilter that implements Filter.
 * The filter is what is in charge of replacing the HttpSession implementation
 * to be backed by Spring Session. In this instance Spring Session is backed by Redis.
 * 
 * 3.We create a RedisConnectionFactory that connects Spring Session to the Redis Server.
 * We use a PropertyPlaceholderConfigurer to externalize the port location.
 * For more information on configuring Spring Data Redis, refer to the reference
 * documentation.
 * 
 * </p>
 * @author lixining
 * @version $Id: SpringSessionConfig.java, v 0.1 2015年6月25日 下午5:39:35 lixining Exp $
 */
@Configuration
@EnableRedisHttpSession
@ConditionalOnWebApplication
@ConditionalOnClass(Session.class)
@AutoConfigureAfter(RedisAutoConfiguration.class)
public class ListeningSpringSessionConfiguration {

    /**
     * Http Session Strategy
     *
     * @return HttpSessionStrategy
     */
    @Bean
    public HttpSessionStrategy httpSessionStrategy() {
        return new CookieAndHeaderHttpSessionStrategy();
    }
}
